home *** CD-ROM | disk | FTP | other *** search
/ Clickx 47 / Clickx 47.iso / assets / software / SyncBack / VirtualBox_1.5.4_Win_x86.msi / vrdpauthsamplefile < prev   
Encoding:
Text File  |  2007-12-29  |  2.4 KB  |  97 lines

  1. /** @file
  2.  *
  3.  * VBox Remote Desktop Protocol:
  4.  * External Authentication Library:
  5.  * Windows Logon Authentication.
  6.  */
  7.  
  8. /*
  9.  * Copyright (C) 2006-2007 innotek GmbH
  10.  *
  11.  * innotek GmbH confidential
  12.  * All rights reserved
  13.  */
  14.  
  15. /* If defined, debug messages will be written to the specified file. */
  16. // #define VRDPAUTH_DEBUG_FILE_NAME "\\VRDPAuth.log"
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20.  
  21. #include <Windows.h>
  22.  
  23. #include <VBox/VRDPAuth.h>
  24.  
  25. static void dprintf(const char *fmt, ...)
  26. {
  27.    va_list va;
  28.  
  29.    va_start(va, fmt);
  30.  
  31.    char buffer[1024];
  32.  
  33.    _vsnprintf (buffer, sizeof (buffer), fmt, va);
  34.  
  35.    OutputDebugStringA(buffer);
  36.  
  37. #ifdef VRDPAUTH_DEBUG_FILE_NAME
  38.    FILE *f = fopen (VRDPAUTH_DEBUG_FILE_NAME, "ab");
  39.    fprintf (f, "%s", buffer);
  40.    fclose (f);
  41. #endif
  42.  
  43.    va_end (va);
  44. }
  45.  
  46. extern "C"
  47. #if defined(_MSC_VER)
  48. __declspec(dllexport)
  49. #endif
  50. VRDPAuthResult VRDPAUTHCALL VRDPAuth (PVRDPAUTHUUID pUuid,
  51.                                       VRDPAuthGuestJudgement guestJudgement,
  52.                                       const char *szUser,
  53.                                       const char *szPassword,
  54.                                       const char *szDomain)
  55. {
  56.     VRDPAuthResult result = VRDPAuthAccessDenied;
  57.  
  58.     LPTSTR lpszUsername = (char *)szUser;
  59.     LPTSTR lpszDomain   = (char *)szDomain;
  60.     LPTSTR lpszPassword = (char *)szPassword;
  61.  
  62.     /* LOGON32_LOGON_INTERACTIVE is intended for users who will be interactively using the computer,
  63.      * such as a user being logged on by a terminal server, remote shell, or similar process.
  64.      */
  65.     DWORD dwLogonType     = LOGON32_LOGON_INTERACTIVE;
  66.     DWORD dwLogonProvider = LOGON32_PROVIDER_DEFAULT;
  67.  
  68.     HANDLE hToken;
  69.  
  70.     dprintf("u[%s], d[%s], p[%s]\n", lpszUsername, lpszDomain, lpszPassword);
  71.  
  72.     BOOL fSuccess = LogonUser(lpszUsername,
  73.                               lpszDomain,
  74.                               lpszPassword,
  75.                               dwLogonType,
  76.                               dwLogonProvider,
  77.                               &hToken);
  78.  
  79.     if (fSuccess)
  80.     {
  81.         dprintf("LogonUser success. hToken = %p\n", hToken);
  82.  
  83.         result = VRDPAuthAccessGranted;
  84.  
  85.         CloseHandle (hToken);
  86.     }
  87.     else
  88.     {
  89.         dprintf("LogonUser failed %08X\n", GetLastError ());
  90.     }
  91.  
  92.     return result;
  93. }
  94.  
  95. /* Verify the function prototype. */
  96. static PVRDPAUTHENTRY gpfnAuthEntry = VRDPAuth;
  97.